<?php

/**
 * 筛选排序-模型
 */
class SortUtil {

    /**
     * 获取价格筛选列表
     * @param int $type
     * @param string $modelName
     * @return boolean
     */
    public static function getPriceBetween($type, $modelName = 'Estate') {
        $arr = array(
            "$modelName.FPRICE <= 50",
            "$modelName.FPRICE <= 80 AND $modelName.FPRICE >= 50",
            "$modelName.FPRICE <= 120 AND $modelName.FPRICE >= 80",
            "$modelName.FPRICE <= 170 AND $modelName.FPRICE >= 120",
            "$modelName.FPRICE <= 230 AND $modelName.FPRICE >= 170",
            "$modelName.FPRICE <= 300 AND $modelName.FPRICE >= 230",
            "$modelName.FPRICE <= 500 AND $modelName.FPRICE >= 300",
            "$modelName.FPRICE >= 500"
        );
        if ($type > 0 && $type <= sizeof($arr)) {
            return $arr[$type - 1];
        } else {
            return false;
        }
    }

    /**
     * 获取面积筛选列表
     * @param int $type
     * @param string $modelName
     * @return boolean
     */
    public static function getAreaBetween($type, $modelName = 'Estate') {
        $arr = array(
            "$modelName.FAREA <= 50",
            "$modelName.FAREA <= 80 AND $modelName.FAREA >= 50",
            "$modelName.FAREA <= 110 AND $modelName.FAREA >= 80",
            "$modelName.FAREA <= 140 AND $modelName.FAREA >= 110",
            "$modelName.FAREA <= 200 AND $modelName.FAREA >= 140",
            "$modelName.FAREA >= 200"
        );
        if ($type > 0 && $type <= sizeof($arr)) {
            return $arr[$type - 1];
        } else {
            return false;
        }
    }

    /**
     * 获取列表排序参数
     * @param int $type
     * @param string $modelName
     * @return boolean|string
     */
    public static function getListSort($type, $modelName = 'Estate') {
        if (is_numeric($type)) {
            $arr = array(
                "$modelName.FID DESC, $modelName.FIMAGES DESC",
                "$modelName.FPRICE DESC, $modelName.FIMAGES DESC",
                "$modelName.FIMAGES DESC"
            );
            if ($type >= 0 && $type <= sizeof($arr)) {
                return $arr[$type];
            } else {
                return false;
            }
        } else {
            return $type;
        }
    }

}
